package com.coocaa.ops.admin.v1.auth.sys.util;

import com.coocaa.ops.admin.base.language.CommonLanguageProperties;
import com.coocaa.ops.common.core.biz.auth.entity.SysUserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

/**
 * @author bijiahao
 * @date : 2019/3/26.
 * @description
 */
@Component
public class SysUserValidator {
    private static CommonLanguageProperties commonLanguageProperties;

    public static void valid(SysUserEntity entity) {
        Assert.notNull(entity, "user info " + commonLanguageProperties.getNotNull());
        if (null == entity.getId()) {
            //新增校验密码，编辑时密码不一定修改，可以为空
            Assert.hasText(entity.getLoginPwd(), "password " + commonLanguageProperties.getNotNull());
        }
        Assert.hasText(entity.getLoginName(), "loginName " + commonLanguageProperties.getNotNull());
        Assert.hasText(entity.getUserName(), "userName" + commonLanguageProperties.getNotNull());
        Assert.hasText(entity.getEmail(), "email " + commonLanguageProperties.getNotNull());
    }

    @Autowired
    public void setCommonLanguageProperties(CommonLanguageProperties commonLanguageProperties) {
        SysUserValidator.commonLanguageProperties = commonLanguageProperties;
    }

}
